/**
 * 题目链接：2025/11/12 考试 T3 最小化
 * 完成时间：2025/11/12 11:39
 * 简要思路：
 */
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;
typedef pair<int, int> Pii;

const int N = 1e6, M = 1e2;
int n, c;
int a[N+5];
LL dp[100005][M+5];

void Sub2() {
	rep(i, 1, n) {
		dp[i][M+1] = 1e18;
		req(j, M, 0) {
			dp[i][j] = dp[i-1][j] + (j < a[i] ? c : j - a[i]);
			dp[i][j] = min(dp[i][j], dp[i][j+1]);
		}
	}
	cout << dp[n][1];
}

void Sub4() {
	LL sum = 0, ans = LL(c) * n;
	rep(i, 1, n) {
		sum += a[i];
		ans = min(ans, LL(i) * a[i] - sum + LL(n-i) * c);
	}
	cout << ans;
}

int main() {
	freopen("minimize.in", "r", stdin);
	freopen("minimize.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> c;
	rep(i, 1, n) cin >> a[i];
	if (!c) {
		cout << 0;
		return 0;
	}
	if (*max_element(a + 1, a + n + 1) <= M) {
		Sub2();
		return 0;
	}
	if (is_sorted(a + 1, a + n + 1)) {
		Sub4();
		return 0;
	}
	cout << LL(c) * n;
	return 0;
}
